package hu.my.bnf.validation;

import static hu.my.bnf.Constants.EMPTY_STRING;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * String Validation.
 */
public final class StringValidation extends Validation {

//--------------------------------------------------------------------------------------------------------------------------------
// Constructors
//--------------------------------------------------------------------------------------------------------------------------------

    /**
     * Suppress default constructor for noninstantiability.
     */
    private StringValidation() {
    }

//--------------------------------------------------------------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------------------------------------------------------------

    /**
     * Get a valid string.
     *
     * @param s String value.
     * @return String valid string.
     */
    @NotNull
    public static String getValidString(@Nullable final String s) {
        return s == null ? EMPTY_STRING : s;
    }

    /**
     * Returns <tt>true</tt> if specified string is <tt>null or </tt> {@link hu.my.bnf.Constants#EMPTY_STRING},
     * otherwise <tt>false</tt>.
     *
     * @param s String
     * @return <tt>true</tt> if value is <tt>null or </tt> {@link hu.my.bnf.Constants#EMPTY_STRING},
     *         otherwise <tt>false</tt>
     */
    public static boolean isEmpty(@Nullable final String s) {
        return (s == null) || EMPTY_STRING.equals(s.trim());
    }
}
